//
//  ZCMainViewController.swift
//  weibo
//
//  Created by Ning Xie on 16/8/8.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class ZCMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
        let zctabBar = ZCTabBar()
        
        
        
        zctabBar.composeButtonClosure = { [weak self] in
            
            let composeVC = ZCComposeViewController()
            composeVC.view.backgroundColor = UIColor.whiteColor()
            let nav = UINavigationController(rootViewController: composeVC)
            
            self!.presentViewController(nav, animated: true, completion: nil)
            
        }
        
        setValue(zctabBar, forKey: "tabBar")
        
        //全局颜色渲染
        UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        //添加自控制器
        addChildViewController(ZCHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(ZCMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(ZCDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ZCProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
    }

    //MARK:添加自控制器
    private func addChildViewController(childController: UIViewController, title: String, imageName: String) {
        
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName+"_selected")
        childController.title = title
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName : UIFont.systemFontOfSize(12)], forState: UIControlState.Normal)
        
        
        let nav = UINavigationController(rootViewController: childController)
        
        addChildViewController(nav)
        
    }
    

  
}
